

def __make_directions():

    class Direction(int):
        """Compass direction. Invert (~) to get the inverse direction, add to it to
        turn clockwise, subtract for counter clockwise. Represented as an integer,
        but casts to string with str()"""
        def __add__(self, other): return Directions[(Directions.index(self) + other) % 4]
        def __sub__(self, other): return self + (4 - int(other) % 4)
        def __invert__(self): return self + 2
        def __str__(self): return ['north', 'east', 'south', 'west'][self]

    class DirectionsType(object):
        """Enum of compass directions - north, south, east, west. Iterable."""
        __slots__ = []
        north = property(lambda self: Directions[0])
        east  = property(lambda self: Directions[1])
        south = property(lambda self: Directions[2])
        west  = property(lambda self: Directions[3])
        def __iter__(self): return iter(Directions)

    Directions = [Direction(0), Direction(1), Direction(2), Direction(3)]
    return DirectionsType()

Directions = __make_directions()

